package Main.day10_10;

import java.util.Scanner;

/**
 * @auther hewenhui
 * @see <a href="hetp://www.codingmaster.com> java </a>
 */
public class test {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        in.nextLine();
        String[] strs = new String[n];
        for (int i = 0; i < n; i++) {
            strs[i] = in.nextLine();
        }
        boolean falg1 = month(strs);
        boolean falg2 = true;
        for (int i = 1; i < n; i++) {
            if (!fun(strs[i], strs[i - 1])) {
                falg2 = false;
                break;
            }
        }



        System.out.println(falg1);
        System.out.println(falg2);
        if(falg1){
            if (falg2) {
                System.out.println("both");
            } else {
                System.out.println("lengths");
            }
        } else {
            if (falg2) {
                System.out.println("lexicographically");

            } else {
                System.out.println("none");

            }
        }
    }
    public static boolean fun(String s1, String s2) {
        int i = 0;
        int j = 0;
        while (i < s1.length() && j < s2.length()) {
            if (s1.charAt(i) > s2.charAt(j)) {
                return true;
            } else if (s1.charAt(i) < s2.charAt(j)) {
                return false;
            } else {
                i++;
                j++;
            }
        }
        if (s1.length() > s2.length())
            return true;
        else
            return false;
    }

    public static boolean month(String[] strs){
        int n=strs.length;
        if(n==0) return true;
        int l=strs[0].length();
        for(int i=1;i<n;i++){
            int L=strs[i].length();
            if(L>l){
                l=L;
            }else{
                return false;
            }
        }
        return true;
    }
}
